package br.com.imob.model.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
import br.com.imob.model.dao.jdbc.JdbcDaoSupport;

import br.com.imob.model.Property;
import br.com.imob.model.mapper.PropertyResultSetExtractor;
import br.com.imob.model.util.Filter;
import br.com.imob.model.dao.PropertyDao;

public class PropertyDaoImpl extends JdbcDaoSupport< Property > implements PropertyDao {

	private static final Logger log = Logger.getLogger( PropertyDaoImpl.class );
	
	public Long saveProperty(Property property) {
		// TODO Auto-generated method stub
		return null;
	}

	public Property findPropertyByID(Long id) {
		// TODO Auto-generated method stub
		return null;
	}

	public void deleteProperty(Long id) {
		// TODO Auto-generated method stub
		
	}

	public void updateProperty(Property property) {
		// TODO Auto-generated method stub
		
	}

	public List< Property > findProperty(Filter filter) {
		
		log.debug( "getting property by filter " + filter.getPrice() );

        String sql = "select * from TBL_PROPERTY where NU_PRICE > ?";
        
        try {
        	List< Property > list = getJdbcTemplate().query( sql, new PropertyResultSetExtractor(), filter.getPrice() );
            return list;
        }
        catch ( EmptyResultDataAccessException ex ){
            return null;
        }
	}
	
	
	private class PropertyRowMapper implements ParameterizedRowMapper<Property>{

        @Override
        public Property mapRow( ResultSet rs, int rowNum ) throws SQLException {
            
            return PropertyResultSetExtractor.fillProperty( rs );
            
        }
        
    }

}
